package com.example.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.api.dto.ResStatusCode;
import com.example.api.entity.Banner;
import com.example.api.exception.CustomException;
import com.example.api.service.IBannerService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 广告轮播 前端控制器
 * </p>
 *
 * @author xushuo
 * @since 2020-09-06
 */
@RestController
@RequestMapping("/api/banner")
public class BannerController {
    private static final Logger log = LoggerFactory.getLogger(BannerController.class);

    @Autowired
            private IBannerService bannerService;


            @GetMapping("/getBanners")
            @ApiOperation("获取广告列表接口")
            public ResponseEntity<List<Banner>>  getBannerList(){

                try {
                    QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();

                    queryWrapper.eq("deleted",0);
            List<Banner> banners = bannerService.list(queryWrapper);

            return ResponseEntity.ok(banners);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            throw new CustomException("", ResStatusCode.BANNER_QUERY_ERROR.getCode(),ResStatusCode.BANNER_QUERY_ERROR.getMessage());
        }


    }



}
